package com.aiwei.tdjk.service.impl;

import com.aiwei.tdjk.bean.Pager;
import com.aiwei.tdjk.dao.extend.CustomsHandbookExtendMapper;
import com.aiwei.tdjk.dto.request.CustomsHandbookPagerRequest;
import com.aiwei.tdjk.entity.CustomsHandbook;
import com.aiwei.tdjk.entity.CustomsHandbookExample;
import com.aiwei.tdjk.enums.CustomsHandbookStatusEnum;
import com.aiwei.tdjk.service.CustomsHandbookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomsHandbookServiceImpl implements CustomsHandbookService{

    @Autowired
    private CustomsHandbookExtendMapper customsHandbookExtendMapper;


    /**
     * 分页查询
     * @param request
     * @return
     */
    @Override
    public Pager<CustomsHandbook> find(CustomsHandbookPagerRequest request) {
        request.webParamConvert();
        List<CustomsHandbook> list = customsHandbookExtendMapper.find(request);
        int totalCount = customsHandbookExtendMapper.getTotalCount(request);
        Pager<CustomsHandbook> pager = new Pager<>();
        pager.setPageNumber(request.getPageNumber());
        pager.setPageSize(request.getPageSize());
        pager.setList(list);
        pager.setTotalCount(totalCount);
        return pager;
    }


    /**
     * 获取
     * @param id
     * @return
     */
    @Override
    public CustomsHandbook get(Long id){
        return customsHandbookExtendMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<CustomsHandbook> getAllAvailable() {
        CustomsHandbookExample example = new CustomsHandbookExample();
        example.or().andStatusEqualTo(CustomsHandbookStatusEnum.unVerification.getCode());
        return customsHandbookExtendMapper.selectByExample(example);
    }


    /**
     * 新增
     *
     * @param customsHandbook
     * @return
     */
    @Override
    public int add(CustomsHandbook customsHandbook) {
        return customsHandbookExtendMapper.insertSelective(customsHandbook);
    }

    /**
     * 更新
     *
     * @param customsHandbook
     */
    @Override
    public void update(CustomsHandbook customsHandbook) {
        customsHandbookExtendMapper.updateByPrimaryKeySelective(customsHandbook);
    }

    /**
     * 删除
     *
     * @param id
     */
    @Override
    public void delete(Long id) {
        customsHandbookExtendMapper.deleteByPrimaryKey(id);
    }

}
